<!DOCTYPE html>
<html>
<head lang="en">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <title>个人信息</title>
    <link type="text/css" rel="stylesheet" href="__STATIC__/home/center/css/mall.css"/>
    <link rel="stylesheet" href="__STATIC__/home/js/layer/theme/default/layer.css">
    <link rel="shortcut icon" href="__STATIC__/home/index/picture/2.png" type="image/x-icon">
</head>
<body class="body_color">
<div id="child_header">
    <div class="goback"><a href="javascript:history.back(-1)"><i></i></a></div>
    <div class="current_location"><span>个人信息</span></div>
    <div class="next_operate"><a id="update" href="javascript:;"><span>保存</span></a></div>
</div>
<div class="user_info">
    <ul>
        <li>
            <span>头像</span>
            <form id="upload_form" method="post" enctype="multipart/form-data">
                <a href="javascript:;">
                    <img style="width: 40px;height: 40px" class="info_input user_photo" src={if condition="(empty($row['user_photo'])) OR ($row['user_photo'] neq 0)"}"__STATIC__/home/common/img/akari.jpg"{else /}"{$row['user_photo']}"{/if} id="photo" onclick="photo_Upload.click()">
                    <input type="file" id="photo_Upload" name="photo" onchange="fileImg()" style="visibility: hidden; position: absolute;" >
                </a>
            </form>
        </li>
        <li><span>昵称</span><input class="info_input user_name" type="text" value="{$row['user_name']}"></li>
        <li>
            <span>性别</span>
            <select class="info_input user_sex select" style="width: 12%">
                <option class="option0" value="0">男</option>
                <option class="option1" value="1">女</option>
            </select>
        </li>
        <li><span>注册时间</span><span class="info_input user_time" >{$row["user_time|date="Y-m-d H:i",###"]}</span></li>
        <li><span>年龄</span><input class="info_input user_age" type="text" value="{$row['user_age']}"></li>
        <li><span>邮箱地址</span><input class="info_input user_email" maxlength="20" type="text" value="{$row['user_email']}"></li>
    </ul>
</div>
</body>
<script src='__STATIC__/home/js/jquery.min.js' type='text/javascript'></script>
<script src="__STATIC__/home/js/layer/layer.js"></script>
<script>

    //提交数据jquery
    $(function() {
        if({$row['user_sex']} == 0){
            $(".option0").attr('selected',"selected");
        }else {
            $(".option1").attr('selected',"selected");
        }



        $('#update').click(function () {

            var data = {};
                data.user_name = $(".user_name").val();
                data.user_sex = $(".select").val();
                data.user_age = $(".user_age").val();
                data.user_email = $(".user_email").val();

            var str = /^-?\d+$/;
            if(!str.test(data.user_age)){
                layer.msg('请输入正确数字年龄!!', {icon: 2,time: 1000});
                return false;

            }
            var reg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
            if (!reg.test(data.user_email)) {

                layer.msg('请输入正确邮箱地址!!', {icon: 2,time: 1000});
                return false;
            }

            $.post("{:url('home/Center/personalInfo')}",data,function (data) {

                if(data > 0){
                    layer.msg('保存成功!!', {icon: 1,time: 500});
                    setTimeout(function () {
                        window.location.href = "{:url('home/center/index')}";
                    }, 500);

                }else {
                    layer.msg('暂未修改!!', {icon: 5,time: 1000});
                }
            })
        })
    })




    /*
     *上传头像
     */
    function fileImg() {

        var upload_form = $("#upload_form")[0];
        var data_obj = new FormData(upload_form);

        layer.load();
        setTimeout(function(){
            layer.closeAll('loading');
        }, 2000);

        $.ajax({
            url: "{:url('home/Center/upload')}",
            method: "POST",
            data: data_obj,
            contentType: false,//文件上传必须
            processData: false,//文件上传必须
            success: function (data) {
                var jost = JSON.parse( data );
                console.log(jost);

                if(jost != 1){

                    layer.msg('上传成功', {icon: 1,time: 2000});

                    var imgUrl = "__UPLOADS__/photo/"+jost;

                    var data ={};
                        data.user_photo = imgUrl;
                    $.post("{:url('home/Center/userPhoto')}",data,function (data) {

                    })
                    $(".user_photo").attr('src',imgUrl);

                }else{
                    layer.msg('上传失败', {icon: 2,time: 2000});

                }
            }
        });
    }

</script>
</html>